import ep from '@/utils/eventproxy';
// import storejs from 'storejs';
import { theme } from '@/consts';

let initState = () => ({
 
});

export default {
  namespace: 'masterGlobal',
  state: { ...initState() },
  effects: {
    // 设置主题
    *setTheme({ payload }, { call, put }) {
      theme.setTheme(payload.theme);
      yield put({ type: 'setState', payload: { theme: payload.theme } });
      ep.emit('themeAfter', payload.theme);
    },
  },
  reducers: {
    setState(state, action) {
      var value = { ...state, ...action.payload };
      ep.emit('masterStateChange', {
        name: 'masterGlobal',
        type: 'setState',
        value: value,
      });
      return value;
    },
    init(state, action) {
      var value = { ...initState(), ...action.payload };
      ep.emit('masterStateChange', {
        name: 'masterGlobal',
        type: 'init',
        value: value,
      });
      return value;
    },
  },
};
